
import proto from "../../../src/lib/net/protobuf/jhaoproto.js"
import { EventManager } from "../../../src/engine/EventManager";
import { HallConfig } from "../config/HallConfig";

export class UserModel {
    public static instance: UserModel = new UserModel()


    public isLogin: boolean = false
    public isLogining: boolean = false

    public account: string;
    public userId: number
    public userName: string;
    public sex: number;
    public userPhoto: string;

    public coins: number;
    public diamond: number;

    public room_id: number = 0
    public clubList: Array<proto.JhaoProto.IClubInfo> = []
    public nowClub: proto.JhaoProto.IClubInfo

    public static proto2Model(userProto: proto.JhaoProto.IUserInfo, model: UserModel = null) {
        if (!model) {
            model = new UserModel()
        }
        model.userId = userProto.userId
        model.userName = userProto.userName
        model.sex = userProto.sex
        model.userPhoto = userProto.userPhoto
        model.coins = userProto.coins
        model.diamond = userProto.diamond

        if (model.userId == UserModel.instance.userId) {
            EventManager.instance.dispatch(HallConfig.Event_Config.Event_Update_UserInfo)
        }
        return model
    }



}